<?php include("includes/session.php"); ?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><?php echo $lang['PAGE_TITLE_ADMIN_NEWS']; ?></title>
<?php include("header.php"); ?>
	<center>
	<table cellpadding="0" cellspacing="0" width="80%">
	<tr>
		<td align="left">
			<?php 
			if($session->userlevel <= 1)
			{
				echo "<center><h2>Restricted Area</h2></center>";
			}
			else
			{
			?>
			<br /><br />
			<center>
			<table cellpadding="10" cellspacing="0" class="border">
			<tr><td class="title" align="left"><?php if(isset($_GET['edit'])){ echo "Edit News"; }else{ echo "Post News"; } ?></td></tr>
			<tr>
				<td>
				<?php
				if($_SESSION['postnewssuccess'])
				{
					echo "<center><h2>News Posted!</h2></center>";
					unset($_SESSION['postnewssuccess']);
				}
				else if($_SESSION['editnewssuccess'])
				{
					echo "<center><h2>News Edited!</h2></center>";
					unset($_SESSION['editnewssuccess']);
				}
				else if(isset($_GET['edit']))
				{
					$result = $database->query("SELECT * FROM ".TBL_NEWS." WHERE id='".$_GET['edit']."'");
					$news = mysql_fetch_array($result);
					$id = $news['id'];
					$title = $news['title'];
					$content = $news['content'];
				?>
				<form action="includes/process.php" method="POST">
				<table cellspacing="0" cellpadding="3">
				<tr>
					<td align="right"><?php echo $lang['ADMIN_NEWS_TITLE']; ?></td>
					<td><input type="text" name="title" maxlength="50" size="79" value="<? echo $title; ?>" style="background-color: #bcc6e1;"></td>
					<td><? echo $form->error("title"); ?></td>
				</tr>
				<tr>
					<td align="right"><?php echo $lang['ADMIN_NEWS_CONTENT']; ?></td>
					<td><textarea name="content" style="background-color: #bcc6e1;" cols="60" rows="10"><? echo $content; ?></textarea></td>
					<td><? echo $form->error("content"); ?></td>
				</tr>
				<tr>
					<td colspan="2" align="right">
						<input type="hidden" name="subEditNews" value="<?php echo $id; ?>">
						<input type="submit" value="Save News">
					</td>
				</tr>
				</table>
				</form>
				<?php
				}
				else
				{
				?>
				<form action="includes/process.php" method="POST">
				<table cellspacing="0" cellpadding="3">
				<tr>
					<td align="right"><?php echo $lang['ADMIN_NEWS_TITLE']; ?></td>
					<td><input type="text" name="title" maxlength="50" size="79" value="<? echo $form->value("title"); ?>" style="background-color: #bcc6e1;"></td>
					<td><? echo $form->error("title"); ?></td>
				</tr>
				<tr>
					<td align="right"><?php echo $lang['ADMIN_NEWS_CONTENT']; ?></td>
					<td><textarea name="content" style="background-color: #bcc6e1;" cols="60" rows="10"><? echo $form->value("content"); ?></textarea></td>
					<td><? echo $form->error("content"); ?></td>
				</tr>
				<tr>
					<td colspan="2" align="right">
						<input type="hidden" name="subPostNews" value="1">
						<input type="submit" value="Post News">
					</td>
				</tr>
				</table>
				</form>
				<?php
				}
				?>
				</td>
			</tr>
			</table>
			</center>
			<br /><br />
			<center>
			<table cellpadding="10" cellspacing="0" class="border" width="90%">
			<tr><td class="title" align="left"><?php echo $lang['ADMIN_NEWS_NEWS']; ?></td></tr>
			<tr><td align="left"><?php displayNewsAdmin(10); ?></td></tr>
			</table>
			</center>
			<?php
			}
			?>
		</td>
	</tr>
	</table>
	</center>
<?php include("footer.php"); ?>